﻿using System;
using System.Collections.Generic;
using System.Text;
using Castle.DynamicProxy;

namespace Micro.Core.ApiConsumer
{
    /// <summary>
    /// 接口调用客户端
    /// 采用Castle动态生成接口类
    /// </summary>
    public static class ApiConsumer
    {
        /// <summary>
        /// 代理生成器
        /// </summary>
        private static ProxyGenerator generator = new ProxyGenerator();

        /// <summary>
        /// 创建接口调用实例
        /// </summary>
        /// <typeparam name="TInterface">泛型对象</typeparam>
        /// <returns></returns>
        public static TInterface Create<TInterface>() where TInterface:class,IDisposable
        {
            var interceptor = new ApiInterceptor();
            return generator.CreateInterfaceProxyWithoutTarget<TInterface>(interceptor);
        }
    }
}
